{% extends "admin/base.html" %} {% block title %}文章列表{% endblock title %} {% block content %}


<nav aria-label="breadcrumb">
    <ol class="breadcrumb">
        <li class="breadcrumb-item active" aria-current="page">文章列表</li>
    </ol>
</nav>


<a class="btn btn-primary" href="/admin/article/add">添加文章</a>

<table style="margin-top:10px;" class="table table-sm">
    <thead>
        <tr>
            <th scope="col">文章标题</th>
            <th scope="col">是否显示</th>
            <th scope="col">优先级</th>
            <th scope="col">操作</th>
        </tr>
    </thead>
    <tbody>
        {% for t in tutorials %}
        <tr>
            <th class="row"><a href="/tutorial/{{t.node.id}}.html" target="blank">{{t.node.title}}</a></th>
            <td>{%if t.node.hidden%}否{%else%}是{%endif%}</td>
            <td>{{t.node.rank}}</td>
            <td>
                <div class="btn-group btn-group-sm" role="group">
                    <a href="/admin/article/edit?edit={{t.node.id}}" class="btn btn-primary">编辑</a>
                    <a href="javascript:void(0)" onclick="deleteArticle('{{t.node.id}}')" class="btn btn-danger">删除</a>
                </div>
            </td>
        </tr>
        {% for t1 in t.children %}
        <tr>
            <td><a href="/tutorial/{{t1.node.id}}.html" target="blank">{{t1.node.title}}</a></td>
            <td>{%if t1.node.hidden%}否{%else%}是{%endif%}</td>
            <td>{{t1.node.rank}}</td>
            <td>
                <div class="btn-group btn-group-sm" role="group">
                    <a href="/admin/article/edit?edit={{t1.node.id}}" class="btn btn-primary">编辑</a>
                    <a href="javascript:void(0)" onclick="deleteArticle('{{t1.node.id}}')" class="btn btn-danger">删除</a>
                </div>
            </td>
        </tr>
        {% endfor %} {% endfor %}
    </tbody>
</table>



{% endblock content %} {% block script %}
<script type="text/javascript">
    function deleteArticle(id) {

        var ret = confirm("确认删除该文章吗?");
        if (!ret) {
            return;
        }

        $.ajax({
            url: "/admin/articles/?delete=" + id,
            type: "delete",
            contentType: "application/json; charset=utf-8",
            success: function(res) {
                if (res.errno == 0) {
                    window.location.reload();
                } else {
                    alert(res.msg);
                }
            },
            error: function(e) {
                alert("错误！！");
            }
        });
    }
</script>
{% endblock script %}